{% load i18n %}

{% for rule in rule_list %}
<tr {% if collapse %}class="active collapse {{ collapse }}{{overwrite_id}}" {% endif %}>
  <td>
    <a title="{{rule.description}}" data-toggle="tooltip" data-placement="right" href="{% url 'rule-detail' rule.id %}">{{ rule.name }}</a>
    {% if rule.parent %}
    <a class="pull-right" title="{% trans "View Parent" %}" href="{% url 'rule-detail' rule.parent.id %}">
      <span class="glyphicon glyphicon-upload"></span>
    </a>
    {% endif %}
    <ul>
      {% for k,v in rule.labels.items|dictsort:0 %}
      <li class="label label-primary">{{k}}:{{v}}</li>
      {% endfor %}
    </ul>
  </td>
  <td {% if not rule.enabled %}class="bg-disabled text-muted" {% endif %} style="word-break: break-word;">{{ rule.clause }}</td>

  <td>{{ rule.duration }}</td>

  {% if toggle %}
  <td style="white-space: nowrap">
    <input type="checkbox" {% if rule.enabled %}checked{% endif %} data-size="mini" data-toggle="toggle" data-csrfmiddlewaretoken="{{csrf_token}}"
      data-action="{% url 'rule-toggle' rule.id %}" />
  </td>
  {% else %}
  <td>&nbsp;</td>
  {% endif %}

  {% if overwrite_id %}
  <td>
    <form method="post" action="{% url 'rule-overwrite' rule.pk %}" style="display: inline">
      <input name="content_type" type="hidden" value="{{overwrite_type}}" />
      <input name="object_id" type="hidden" value="{{overwrite_id}}" />
      {% csrf_token %}
      <button class="btn btn-warning btn-xs">{% trans "Overwrite" %}</button>
    </form>
  </td>
  {% else %}
  <td>
    <form method="post" action="{% url 'rule-delete' rule.id %}" onsubmit="return confirm('{% trans "Delete this Rule?" %}')" style="display: inline">
      {% csrf_token %}
      <button class="btn btn-danger btn-xs">{% trans "Delete" %}</button>
    </form>
  </td>
  {% endif %}
</tr>
{% empty %}
{% if show_empty %}
<tr>
  <td colspan=5>No rules found for {{show_empty}}</td>
</tr>
{% endif %}
{% endfor %}
